package a66weding.com.jiehuntong.activity.me;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.HashMap;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.beans.CommonResultBean;
import a66weding.com.jiehuntong.beans.ErrorBean;
import a66weding.com.jiehuntong.beans.HttpRequestBean;
import a66weding.com.jiehuntong.beans.SuccessBean;
import a66weding.com.jiehuntong.common.utils.CUtils;
import a66weding.com.jiehuntong.http.HttpHandleUtil;
import a66weding.com.jiehuntong.http.OnNetResultListener;
import a66weding.com.jiehuntong.http.RequestCode;
import a66weding.com.jiehuntong.http.UrlDealUtil;

/**
 * 这是我的-设置-意见反馈的界面
 */
public class MeSetSuggestActivity extends MeBaseActivity implements View.OnClickListener  , CompoundButton.OnCheckedChangeListener, OnNetResultListener {
    private LinearLayout mBackLay;
    private TextView mBackContentTv;
    private TextView mHeaderTitleTv;
    private RelativeLayout mHeaderRightRlay;
    private Button mCommitBtn;
    private EditText mOpinion;
    private EditText meContact;
    private String feedBack;
    private String contactWay;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_me_set_suggest);
        initview();
    }


    private void initview() {
        mBackLay = (LinearLayout) findViewById(R.id.llay_header_back);
        mBackContentTv = (TextView) findViewById(R.id.tv_header_backcontent);
        mHeaderTitleTv = (TextView) findViewById(R.id.tv_header_title);
        mHeaderRightRlay = (RelativeLayout) findViewById(R.id.rlay_header_rightfunc);
        mCommitBtn = (Button) findViewById(R.id.btn_commit);
        mOpinion = (EditText) findViewById(R.id.et_me_setsuggest_content);
        meContact = (EditText) findViewById(R.id.et_me_setsuggest_contact);
        mBackContentTv.setText("返回");
        mHeaderTitleTv.setText("意见反馈");
        mHeaderRightRlay.setVisibility(View.GONE);
        mCommitBtn.setText("发送");
        mBackLay.setOnClickListener(this);
        mCommitBtn.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.llay_header_back: //点击返回，关闭界面
                finish();
                break;
            case R.id.btn_commit: //发送按钮,把自己的意见发送给服务器
                feedBack = mOpinion.getText().toString().trim();
                contactWay = meContact.getText().toString().trim();
                if(TextUtils.isEmpty(feedBack)) {
                    CUtils.showToast("意见不能为空");
                    return;
                } else if(TextUtils.isEmpty(contactWay)) {
                    CUtils.showToast("联系方式不能为空");
                    return;
                }
                String url= UrlDealUtil.getRealUrl(RequestCode.UPDATE_FEEDBACK);
                HashMap<String,String> requestParams=new HashMap<String,String>();
                requestParams.put("FeedBack",""+feedBack);
                requestParams.put("ContactWay",""+contactWay);
                HttpRequestBean httpRequestBean = new HttpRequestBean(RequestCode.POSTEQUEST, url,
                        this, CommonResultBean.class, RequestCode.UPDATE_FEEDBACK, requestParams);
                HttpHandleUtil.executeCommonPost(this,httpRequestBean);

                break;
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

    }

    @Override
    public void onSucess(SuccessBean sucessbean) {
        Object data = sucessbean.getData();
        CommonResultBean commonResultBean = (CommonResultBean) data;
        if ("0000".equals(commonResultBean.getResCode())) {
            Toast.makeText(this,"提交意见成功~感谢您的反馈,谢谢",Toast.LENGTH_SHORT).show();
            finish();
        }
    }

    @Override
    public void onError(ErrorBean errorBean) {
        Toast.makeText(this,"数据请求失败",Toast.LENGTH_SHORT).show();
    }

}
